import { ipcMain } from "electron";
import { notify } from "../notification";
import { openUrl } from "../shell";
import { addFlashingPath, deleteFlashingPath, enableTray, endFlashing, startFlashing } from "../tray";
import { createWindow, maxOrMinWindow, maxWindow, minWindow, shrinkWindow, updateWindowSize } from "../window";

/**
 * @description 初始化ipc通信
 * @export
 */
export function initNotification(){
  //  窗口
  ipcMain.on('window.send', (e, arg) => {
    notify(arg.title, arg.body);
  });
  ipcMain.on('window.updateWindowSize', (e, arg) => {
    updateWindowSize(arg.width, arg.height,arg.animate,arg.tag);
  });
  ipcMain.on('window.minWindow', (e, arg) => {
    minWindow(arg.tag);
  });
  ipcMain.on('window.maxWindow', (e, arg) => {
    maxWindow(arg.tag);
  });
  ipcMain.on('window.maxOrMinWindow', (e, arg) => {
    maxOrMinWindow(arg.tag);
  });
  ipcMain.on('window.shrinkWindow', (e, arg) => {
    shrinkWindow(arg.tag);
  });
  ipcMain.on('window.createWindow', (e, arg) => {
    createWindow(arg.winConfig, arg.path);
  });
  
  //  托盘事件
  ipcMain.on('tray.startFlashing', (e, arg) => {
    startFlashing(arg.time );
  });
  ipcMain.on('tray.enableTray', (e, arg) => {
    enableTray(arg.path );
  });
  ipcMain.on('tray.addFlashingPath', (e, arg) => {
    addFlashingPath(arg.path );
  });
  ipcMain.on('tray.deleteFlashingPath', (e, arg) => {
    deleteFlashingPath(arg.path );
  });
  ipcMain.on('tray.endFlashing', (e, arg) => {
    endFlashing();
  });

  // 默认应用程序事件
  ipcMain.on('shell.openUrl', (e, arg) => {
    openUrl(arg.path);
  });  
}

/**
 * @description 初始化ipc通信
 * @export
 */
export function initIpcMain(){
  initNotification();
}